package com.game.centerserver.infrastructure.service.impl;

import com.game.centerserver.infrastructure.entity.Order;
import com.game.centerserver.infrastructure.dao.OrderDao;
import com.game.centerserver.infrastructure.service.OrderService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * (Order)表服务实现类
 *
 * @author makejava
 * @since 2024-11-19 15:52:46
 */
@Service("orderService")
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param orderNum 主键
     * @return 实例对象
     */
    @Override
    public Order queryById(String orderNum) {
        return this.orderDao.queryById(orderNum);
    }

    @Override
    public List<Order> query(Order order) {
        return orderDao.query(order);
    }

    /**
     * 新增数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public Order insert(Order order) {
        order.setOrderNum(UUID.randomUUID().toString());
        if (order.getStartTime() == null) {
            order.setStartTime(new Date());
        }
        if (order.getCreateTime() == null) {
            order.setCreateTime(new Date());
        }
        if (this.orderDao.insert(order) <= 0) {return null;}
        return order;
    }

    /**
     * 修改数据
     *
     * @param order 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(Order order) {

        return this.orderDao.update(order) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param orderNum 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String orderNum) {
        return this.orderDao.deleteById(orderNum) > 0;
    }
}
